#pragma once
#include <iostream>
#include <boost/asio.hpp>
#include <memory>
#include "MsgNode.h"
#include <mutex>
#include <queue>
class Server;
class Session:public std::enable_shared_from_this<Session>
{
public:
	Session(boost::asio::io_context& ioc,Server *);
	~Session();
	void Start();
	void Send(short msg_id,const char *msg,short max_size);
	void CloseSession();
	std::string GetUuid();
	boost::asio::ip::tcp::socket& GetSocket();
private:
	void HandleWrite(std::shared_ptr<Session> session, const boost::system::error_code& e);
	boost::asio::ip::tcp::socket _sock;
	boost::asio::io_context& _ioc;
	std::shared_ptr<MsgNode> _recv_head_node;
	std::shared_ptr<RecvNode> _recv_msg_node;
	std::string _uuid;
	Server* _server;
	bool _b_stop;
	std::mutex _mutex;
	std::queue<SendNode> _send_queue;
};

